package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.EnLinkProductDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.enlink.EnLinkProduct;

@Repository("enLinkProductDAO")
public class EnLinkProductDAOImpl extends SuperDAO<EnLinkProduct> implements
		EnLinkProductDAO {

	@Override
	public void insert(EnLinkProduct productInfo) {
		this.getSqlSession().insert("mybatis.xml.EnLinkProductMapper.insert",
				productInfo);
	}

	@Override
	public EnLinkProduct queryByProductId(String productId) {
		EnLinkProduct product = this.getSqlSession().selectOne(
				"mybatis.xml.EnLinkProductMapper.queryByProductId", productId);
		return product;
	}

	@Override
	public Pagination<EnLinkProduct> queryPaginationList(
			EnLinkProduct enLinkGoodsInfo) {
		Pagination<EnLinkProduct> paginationList = null;
		Integer rowCount = queryRowCount(enLinkGoodsInfo);

		enLinkGoodsInfo.calculate();
		List<EnLinkProduct> list = queryGoodsInfoList(enLinkGoodsInfo);
		paginationList = this.queryPagination(rowCount, list, enLinkGoodsInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(EnLinkProduct enLinkGoodsInfo) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EnLinkProductMapper.queryRowCount",
				enLinkGoodsInfo);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<EnLinkProduct> queryGoodsInfoList(EnLinkProduct enLinkGoodsInfo) {
		List<EnLinkProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.EnLinkProductMapper.queryEnlinkGoodsInfoList",
				enLinkGoodsInfo);
		return list;
	}

	@Override
	public List<EnLinkProduct> queryAllProductInfo(String state) {
		List<EnLinkProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.EnLinkProductMapper.queryAllProductInfo", state);
		return list;
	}

	@Override
	public void updateState(EnLinkProduct enLinkGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.EnLinkProductMapper.updateState", enLinkGoodsInfo);
	}

	@Override
	public List<String> queryAllProductId() {
		List<String> productIdList = this.getSqlSession().selectList(
				"mybatis.xml.EnLinkProductMapper.queryAllProductId");
		return productIdList;
	}

	/**
	 * 商品更新
	 * 
	 * @param enLinkGoodsInfo
	 */
	@Override
	public void update(EnLinkProduct enLinkGoodsInfo) {
		this.getSqlSession().update("mybatis.xml.EnLinkProductMapper.update",
				enLinkGoodsInfo);
	}

}
